package com.wgchao.authmanager.application;

import com.alibaba.fastjson.JSON;
import com.wgchao.authmanager.infrastructure.resp.BackResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: GlobalExceptionHandler
 * @author: wgchao
 * @createTime: 2019/9/3 11:12 AM
 * @Description: 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public BackResult exceptionHandler(HttpServletRequest request, Exception exception) throws Exception {
        return handleErrorInfo(request, exception.getMessage(), exception);
    }

    private BackResult<String> handleErrorInfo(HttpServletRequest request, String message, Exception exception) {
        exception.printStackTrace();
        return BackResult.fail().setMsg(message);
    }
}
